[Flex] Bill HTTP-prescaled instances as AlwaysReady baseline until first execution - #11900
Open
Mani (manikantanallagatla) wants to merge 2 commits into
Open
[Flex] Bill HTTP-prescaled instances as AlwaysReady baseline until first execution#11900Mani (manikantanallagatla) wants to merge 2 commits into
Mani (manikantanallagatla) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mani (manikantanallagatla)
marked this pull request as ready for review
September 7, 2026 05:36
Copilot started reviewing on behalf of
Mani (manikantanallagatla)
September 7, 2026 05:37
View session
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
This change affects billing-routing semantics for Flex prescaling, so it warrants final human review despite the added targeted test coverage.
Pull request overview
Implements Flex Consumption “deferred-on-demand” prescaling billing by treating prescaled-but-unused instances as AlwaysReady baseline (via metrics stamping) until the first function execution, after which the instance permanently transitions to normal OnDemand billing behavior.
Changes:
- Introduces
FUNCTIONS_PRESCALED_INSTANCEand uses it to publish zero-activity baseline metrics stampedIsAlwaysReady=trueuntil first execution. - Permanently flips prescaled instances to
IsAlwaysReady=falseon firstOnFunctionStarted, ensuring subsequent intervals route to OnDemand. - Adds targeted unit tests covering unused baseline publishing, first-execution transition (including during an in-flight publish), and post-execution idle behavior.
File summaries
| File | Description |
|---|---|
| test/WebJobs.Script.Tests/Metrics/FlexConsumptionMetricsPublisherTests.cs | Adds prescaled-instance billing behavior coverage and adjusts publisher creation to inject configuration / mock metrics provider. |
| src/WebJobs.Script/Environment/EnvironmentSettingNames.cs | Adds FUNCTIONS_PRESCALED_INSTANCE constant. |
| src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs | Injects IConfiguration into FlexConsumptionMetricsPublisher construction for Flex SKU. |
| src/WebJobs.Script.WebHost/Metrics/FlexConsumptionMetricsPublisher.cs | Implements prescaled detection and AlwaysReady-baseline stamping until first execution is observed. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+345
to
+350
| var configuration = s.GetService<IConfiguration>(); | ||
| var options = s.GetService<IOptions<FlexConsumptionMetricsPublisherOptions>>(); | ||
| var standbyOptions = s.GetService<IOptionsMonitor<StandbyOptions>>(); | ||
| var logger = s.GetService<ILogger<FlexConsumptionMetricsPublisher>>(); | ||
| var metricsProvider = s.GetService<IHostMetricsProvider>(); | ||
| return new FlexConsumptionMetricsPublisher(environment, standbyOptions, options, logger, new FileSystem(), metricsProvider); | ||
| return new FlexConsumptionMetricsPublisher(environment, configuration, standbyOptions, options, logger, new FileSystem(), metricsProvider); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
HTTP prescaling pre-warms Flex Consumption instances before load, but today their reserved warm time is not billed. This implements the approved v1 deferred-on-demand design: reuse the existing AlwaysReady baseline meter while a prescaled instance is unused, then switch to normal OnDemand billing when it serves its first execution.
This avoids introducing a new Commerce meter, following Thiago's guidance that meter sprawl carries a 6+ month delivery risk.
What changed
FUNCTIONS_PRESCALED_INSTANCEhost environment setting.IsAlwaysReady=true, which routes them to the existing AlwaysReady baseline meter.OnFunctionStartedpermanently flips that instance to OnDemand before the serving interval is metered.Compatibility
The change is inert until the appserver injects
FUNCTIONS_PRESCALED_INSTANCE=1.Cross-component contract
The cv2 appserver implementation in AAPT-Antares-Functions-Docker PR 16449382 (
developer/balag/prescale) must:FUNCTIONS_PRESCALED_INSTANCE=1on prescaled pods; andBalaji Balakrishnan (@bala): please confirm
FUNCTIONS_PRESCALED_INSTANCEis the agreed environment-variable name.Billing routing
No Legion code change is required.
NestedRoleFunctionsMetricsCollectoralready groups and routes billing usingMetrics.IsAlwaysReady, so the host's effective stamp selects the existing AlwaysReady meter.Design: Legion PR 16487726 (
docs/functions/prescaling-billing-design.md).Tests
dotnet test test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj --filter "FullyQualifiedName~FlexConsumptionMetricsPublisherTests"Passed: 13, Failed: 0, Skipped: 0. The existing real-AlwaysReady theory also passed both cases unchanged.